﻿@using MvcApplication4.Models
@model IEnumerable<LOTE>

@{
    ViewBag.Title = "Lotes Cadastrados";
    //Layout = "~/Views/Shared/_Layout.cshtml";
}

<h2>Lotes Cadastrados</h2>
<br/>
    @Html.ActionLink("Cadastrar Lote", "Create", "CadastroLote")
<br/>
<br/>

    @{
        Html.Syncfusion().Grid<LOTE>("GenericListGrid")
            .Datasource(Model)
            .Caption("Lotes Cadastrados")
            .EnablePaging()
            .EnableSorting()
            .EnableFiltering()
            .AutoFormat(Skins.Turquoise)
            .ClientSideEvents(e => e.OnToolbarClickEvent("pdf_export"))
             .ToolBar(toolbar =>
             {
                 toolbar.Add(GridToolBarItems.ExcelExport, "Excel")
                        .Add(GridToolBarItems.WordExport, "Word")
                        .Add(GridToolBarItems.PDFExport, "PDF");
             })
            .Mappers(map =>
            {
                map.ExportExcelAction("ExportToExcel")
                   .ExportWordAction("ExportToWord")
                   .ExportPdfAction("ExportToPDF");
            })
            .Column(cols =>
                {
                    cols.Add(c => c.ID_Lote).HeaderText("ID").TextAlign(Syncfusion.Mvc.Grid.TextAlignment.Right).Width(110);
                    cols.Add(c => c.tb_Vacina.Nome_Vacina).HeaderText("Nome Vacina");
                    cols.Add(c => c.tb_Laboratorio.Nome_Laboratorio).HeaderText("Nome Laboratório");
                    cols.Add(c => c.Validade).HeaderText("Validade");
                    cols.Add(c => c.Num_Doses).HeaderText("Número de Doses  ");
                    cols.Add("Editar").HeaderText("Editar").Format("<a href=/CadastroLote/Edit/{ID_Lote}>Editar</a>").Width(60);
                    cols.Add("Deletar").HeaderText("Deletar").Format("<a href=/CadastroLote/Delete/{ID_Lote}>Deletar</a>").Width(60);
                }).Render();
    }
    
    <script type="text/javascript">

        function pdf_export(sender, args) {



            if (args._currentItemId == sender._ID + 'pdf_export'

            || args._currentItemId == sender._ID + 'word_export'

            || args._currentItemId == sender._ID + 'excel_export') {

                var _VisibleColumns = new Array();

                $.each(sender.get_VisibleColumns(), function (index, Column) {

                    if (Column.Name == "Editar") {

                        Column.Visible = false; //removing columns for export

                    }

                    if (Column.Name == "Deletar") {

                        Column.Visible = false; //removing columns for export

                    }

                    if (Column.Visible == true) {

                        _VisibleColumns.push(Column); //visible columns

                    }

                });

                sender.set_VisibleColumns(Sys.Serialization.JavaScriptSerializer.serialize(_VisibleColumns)); //Set visible columns.

            }

        }

 

</script>